﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AngajezBona.CaptchaImage
{
    public partial class CapchaButton : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)CodVeridficareImg_Click(null, null);
        }
        private static Random random = new Random();
        private string GenerateRandomCode()
        {
            string s = String.Empty;
            for (int i = 0; i < 6; i++)
            {
                char temp = 'a';
                switch (random.Next(2))
                {
                    case 0: temp = (char)random.Next(49, 57); break;
                    case 1: temp = (char)random.Next(65, 90); break;
                }
                s += temp.ToString();
            }
            return s;
        }
        protected void CodVeridficareImg_Click(object sender, ImageClickEventArgs e)
        {
            Session["CaptchaImageText"] = GenerateRandomCode();
        }
    }
}